package caffeinebeveragecase;

/**
 * description:
 *  咖啡因饮料基类
 * @author Yuanml on 2020/10/16 18:24
 */
public abstract class CaffeineBeverage {
    private String name;
    CaffeineBeverage(String name){
        this.name = name;
    }
    public final void prepare() {
        boilWater();
        brew();
        pourInCup();
        if (isAddCondiments()) {
            addCondiments();
        }
    }

    /**
     * 将水煮沸
     */
    public final void boilWater(){
        System.out.println("将水煮沸");
    }

    /**
     * 浸泡
     */
    public abstract void brew();

    /**
     * 装入杯子
     */
    public final void pourInCup(){
        System.out.println("将" + name + "装杯");
    }

    /**
     * 添加佐料
     */
    public abstract void addCondiments();

    /**
     * 钩子函数
     * @return  返回是否需要添加配料
     */
    public boolean isAddCondiments() {
        return true;
    }
}
